//
// Constant Buffer Variables
//

SamplerState samLinear
{
    Filter = MIN_MAG_MIP_LINEAR;
    AddressU = Wrap;
    AddressV = Wrap;
	AddressW = Wrap;
};

TextureCube EnvMap;

cbuffer camera_cbuffer
{
	//transformation
    matrix View;
    matrix Projection;
    matrix World;
};

cbuffer cbChangesEveryFrame
{
	//material
	float3 Kd;
};

struct VS_INPUT
{
    float3 Pos          : POSITION;         //position
};

struct PS_INPUT
{
	float4 Pos : SV_POSITION;
	float3 WorldPos : TEXCOORD0;
};

//--------------------------------------------------------------------------------------
// DepthStates
//--------------------------------------------------------------------------------------
DepthStencilState DisableDepthWrite
{
    DepthEnable = TRUE;
    DepthWriteMask = ZERO;
};

BlendState NoBlending
{
    AlphaToCoverageEnable = FALSE;
    BlendEnable[0] = FALSE;
};

BlendState AlphaBlending
{
    AlphaToCoverageEnable = FALSE;
    BlendEnable[0] = TRUE;
    SrcBlend = SRC_ALPHA;
    DestBlend = INV_SRC_ALPHA;
    BlendOp = ADD;
    SrcBlendAlpha = ZERO;
    DestBlendAlpha = ZERO;
    BlendOpAlpha = ADD;
    RenderTargetWriteMask[0] = 0x0F;
};

RasterizerState NoCulling
{
    CullMode = BACK;
};

//
// Vertex Shader
//
PS_INPUT VS(VS_INPUT input)
{
    PS_INPUT output = (PS_INPUT)0;
	output.WorldPos = input.Pos;
	output.Pos = mul( float4(input.Pos,1), World );
    output.Pos = mul( output.Pos, View );
    output.Pos = mul( output.Pos, Projection );
	return output;
}

//
// Pixel Shader
//
float4 PS(PS_INPUT input) : SV_Target
{
	//return float4(normalize(input.WorldPos), 1.0f);
	return EnvMap.Sample(samLinear, normalize(input.WorldPos));
	//return float4(input.WorldPos, 1.0f);
}

//
// Technique
//
technique10 Render
{
    pass P0
    {
        SetVertexShader( CompileShader( vs_4_0, VS() ) );
        SetGeometryShader( NULL );
        SetPixelShader( CompileShader( ps_4_0, PS() ) );
        
        SetDepthStencilState( DisableDepthWrite, 0 );
        SetBlendState( NoBlending, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF );
		SetRasterizerState( NoCulling );
    }
};
